package org.jadestudio.home.dao;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.ibatis.sqlmap.client.SqlMapClient;;

public class CommonDao {
	private SqlMapClient sqlMapClient;
	public SqlMapClient getSqlMapClient() {
		return sqlMapClient;
	}

	public void setSqlMapClient(SqlMapClient sqlMapClient) {
		this.sqlMapClient = sqlMapClient;
	}
	
	
	
	public static String getIP(HttpServletRequest request) {  
		String ip = request.getHeader("x-forwarded-for");  
		if (!checkIP(ip)) {  
			ip = request.getHeader("Proxy-Client-IP");  
		}  
		if (!checkIP(ip)) {  
			ip = request.getHeader("WL-Proxy-Client-IP");  
		}  
		if (!checkIP(ip)) {  
			ip = request.getRemoteAddr();  
		}  
		return ip;  
	}  

	private static boolean checkIP(String ip) {  
		if (ip == null || ip.length() == 0 || "unkown".equalsIgnoreCase(ip)  
			|| ip.split(".").length != 4) {  
			return false;  
		}  
		return true;  
	}  

	public static boolean isNullOrEmpty(Object s){
		if (s==null) return true;
		return (s.toString().trim().length()==0);
	}
	
	public static boolean isGreaterThanZero(Object i){
		if (i==null) return false;
		long ii = (Long)i;
		return (ii>0);
	}
}
